import axios from 'axios'
import { message } from 'antd'
const instance = axios.create({
    timeout: 10 * 1000
})
// 添加响应拦截
instance.interceptors.response.use(
    res => {
        const resDate = (res.data || {}) as ResType
        const { errno, data, msg } = resDate
        if (errno !== 0) {
            if (msg) {
                message.error(msg)
            }
            throw new Error(msg)
        }

        return data as any
    })
export default instance

export type ResType = {
    errno: number,
    data?: ResDataType,
    msg?: string
}

export type ResDataType = {
    [key: string]: any
}